package com.sina.auto.components.AddContentImpl;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

import static com.sina.auto.components.AddContentImpl.ImageUtil.MergeImage.mergeImage;
import static com.sina.auto.components.AddContentImpl.ImageUtil.imageCut;

public class UploadAddParagraph implements com.sina.auto.components.AddContentInterface.UploadAddParagraph {
    @Override
    public BufferedImage uploadAddPara(String[] Content, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addParagByMerge(imgs[1],Content) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddPara(String[] Content, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addParagByMerge(imgs[1],Content) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadAddPara(String[] Content, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addParagByMerge(imgs[1],Content) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddParaAuthor(String[] Content, String author, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addParagByMergeAddAuthor(imgs[1],Content,author) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddParaAuthor(String[] Content, String author, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addParagByMergeAddAuthor(imgs[1],Content,author) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadAddParaAuthor(String[] Content, String author, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addParagByMergeAddAuthor(imgs[1],Content,author) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddParaTitle(String[] Content, String title, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addParagByMergeAddTiltle(imgs[1],Content,title) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddParaTitle(String[] Content, String title, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addParagByMergeAddTiltle(imgs[1],Content,title) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadAddParaTitle(String[] Content, String title, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addParagByMergeAddTiltle(imgs[1],Content,title) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddPara(String[] Content, String author, String title, File file) throws Exception {
        BufferedImage imgs[] = imageCut(file);

        BufferedImage[] images = {imgs[0],AddString.addParagByMerge(imgs[1],Content,author,title) ,imgs[2]};

        return mergeImage(images,2);
    }

    @Override
    public BufferedImage uploadAddPara(String[] Content, String author, String title, BufferedImage[] imgs) throws Exception {
        if(imgs.length == 3) {

            BufferedImage[] images = {imgs[0],AddString.addParagByMerge(imgs[1],Content,author,title) ,imgs[2]};

            return mergeImage(images, 2);
        }
        else{
            return null;
        }
    }

    @Override
    public BufferedImage uploadAddPara(String[] Content, String author, String title, String file1, String file2, String file3) throws Exception {
        BufferedImage[] imgs = {ImageIO.read(new File(file1)),ImageIO.read(new File(file2)),ImageIO.read(new File(file3))};

        BufferedImage[] images = {imgs[0],AddString.addParagByMerge(imgs[1],Content,author,title) ,imgs[2]};

        return mergeImage(images,2);
    }
}
